﻿using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ModuleA.ViewModels
{
	internal class ViewAViewModel : BindableBase,IConfirmNavigationRequest
	{
		private string msg;
		/// <summary>
		/// 显示的内容
		/// </summary>
		public string Msg
		{
			get { return msg; }
			set
			{
				msg = value;
				RaisePropertyChanged("Msg");
			}
		}

		public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
		{
			bool result = true;
			if(MessageBox.Show("确认切换吗？", "温馨提示", MessageBoxButton.YesNo) == MessageBoxResult.No)
			{
				result = false;
			}
			continuationCallback?.Invoke(result);
		}

		/// <summary>
		/// 是否重用实例
		/// </summary>
		/// <param name="navigationContext"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		public bool IsNavigationTarget(NavigationContext navigationContext)
		{
			return true;
		}

		public void OnNavigatedFrom(NavigationContext navigationContext)
		{
			
		}

		/// <summary>
		/// 接收到数据
		/// </summary>
		/// <param name="navigationContext"></param>
		public void OnNavigatedTo(NavigationContext navigationContext)
		{
			if (navigationContext.Parameters.ContainsKey("MsgA"))
			{
				//Msg = (string)navigationContext.Parameters["MsgA"];
				Msg = navigationContext.Parameters.GetValue<string>("MsgA");
			}
		
		}
	}
}
